package com.dq.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dq.health.dao.notify.SysNotifyMapper;
import com.dq.health.dto.request.notify.QueryNotifyParam;
import com.dq.health.entity.notify.SysNotify;
import com.dq.health.service.IAPINotifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <>
 *
 * @Author: chenxin
 * @Date: 2021/5/17
 */
@Service
public class NotifyServiceImpl implements IAPINotifyService {

    @Resource
    SysNotifyMapper sysNotifyMapper;

    @Override
    public Long addNotify(SysNotify sysNotify) {
        sysNotifyMapper.insert(sysNotify);
        return sysNotify.getSysNotifyId();
    }

    @Override
    public SysNotify getNotifyById(Long id) {
        return sysNotifyMapper.selectById(id);
    }

    @Override
    public IPage<SysNotify> listNotify(QueryNotifyParam param) {
        IPage<SysNotify> page = new Page<>(param.getPage(), param.getPageSize());

        LambdaQueryWrapper<SysNotify> queryWrapper = new LambdaQueryWrapper<>();
        if (param.getReceiveUserId() != null) {
            queryWrapper.eq(SysNotify::getReceiveUserId, param.getReceiveUserId());
        }
        if (param.getStatus() != null) {
            queryWrapper.eq(SysNotify::getStatus, param.getStatus());
        }

        return sysNotifyMapper.selectPage(page, queryWrapper);
    }

    @Override
    public void updateNotify(SysNotify sysNotify) {
        sysNotifyMapper.updateById(sysNotify);
    }
}
